﻿using Service.Auth.Domain.AggregatesModel;
using Service.Core.Redis.Aop.Cache;
using Service.Core.Repository;
using Service.Framework;

namespace Service.Auth.Api.Application.Query
{
    /// <summary>
    /// 授权客户端查询器
    /// </summary>
    /// <param name="clientRepository"></param>
    public class AuthClientQueryService(IRepository<AuthClient> clientRepository) : IScopedService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public async Task<AuthClient> QueryClientByClientId(string clientId)
        {
            var clients = await QueryClientList();
            var client = clients.FirstOrDefault(s => s.ClientId.Equals(clientId));
            return client;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [RedisCacheInterceptor($"{nameof(AuthClientQueryService)}:{nameof(QueryClientList)}",cacheDuration: 60 * 60 * 12)] //AOP缓存,虚方法
        protected virtual async Task<List<AuthClient>> QueryClientList()
        {
            return await clientRepository.GetListAsync();
        }
    }
}